package tomcat;

import java.util.concurrent.BlockingQueue;

public class PoolThread extends Thread {
    private BlockingQueue<Runnable> queue;
    private ThreadPool threadPool;
    private boolean isStopped;

    public PoolThread(BlockingQueue<Runnable> queue, ThreadPool threadPool) {
        this.queue = queue;
        this.threadPool = threadPool;
    }

    @Override
    public void run() {
        while (!isStopped()) {
            try {
                threadPool.doWork();
            } catch (Exception e) {
                // log error
            }
        }
    }

    public synchronized void doStop() {
        isStopped = true;
        this.interrupt();
    }

    public synchronized boolean isStopped() {
        return isStopped;
    }
}